package com.gjy.ds.sort_search;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-15 14:56:20
 */
public class SortTest {

    private Sort sort;
    private Sort9 sort9;
//    private static final Integer SIZE = 8000000;
    private static final Integer SIZE = 20;
    private int[] array = new int[SIZE];

    @BeforeEach
    public void before() {
        sort = new Sort();
        sort9 = new Sort9();
        for (int i = 0; i < SIZE; i++) {
            array[i] = ThreadLocalRandom.current().nextInt(20);
        }
        System.out.println("原始数组: " + Arrays.toString(array));
    }

    @Test
    public void test16() {
        sort9.quick(array, 0, array.length - 1);
    }

    @Test
    public void test15() {
        sort9.shell1(array);
    }

    @Test
    public void test14() {
        sort9.insert(array);
    }

    @Test
    public void test13() {
        sort9.select(array);
    }

    @Test
    public void test12() {
        sort9.select2(array);
    }

    @Test
    public void test11() {
        sort9.bubble(array);
    }

    @Test
    public void test10() {
        int[] array = {1, 2};
        sort9.swap(array, 0, 1);
        System.out.println(Arrays.toString(array));
    }

    @Test
    public void quick() {
        sort.quick(array, 0, array.length - 1);
        System.out.println("排序数组: " + Arrays.toString(array));
    }

    @Test
    public void shell() {
        sort.shell(array);
        System.out.println("排序数组: " + Arrays.toString(array));
    }

    @Test
    public void insert() {
        sort.insert(array);
        System.out.println("排序数组: " + Arrays.toString(array));
    }

    @Test
    public void select() {
        sort.select(array);
        System.out.println(Arrays.toString(array));
    }

    @Test
    public void bubble1() {
        sort.bubble1(array);
        System.out.println(Arrays.toString(array));
    }

    @Test
    public void bubble0() {
        sort.bubble0(array);
        System.out.println(Arrays.toString(array));
    }

    @Test
    public void test1() {
        int[] a = {1, 2, 3};
        sort.swap(a, 0, 2);
        assertEquals(Arrays.toString(new int[]{3, 2, 1}), Arrays.toString(a));
    }

    @AfterEach
    public void after() {
        System.out.println("排序数组: " + Arrays.toString(array));
        sort = null;
        array = null;
    }
}
